package com.zhouyx.userservice.controller;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @title: CustomMetricsController
 * @Author: max.zhou1
 * @Date: 2024/10/15 11:23
 * @Version: 1.0
 * https://blog.csdn.net/ximaiyao1984/article/details/132698762   ！！！！
 * https://www.51cto.com/article/777950.html  ！！！！！
 * https://juejin.cn/post/6872912858670170120
 * https://cloud.tencent.com/developer/article/1477642
 * http://localhost:8081/actuator
 * http://localhost:8081/actuator/metrics
 * http://localhost:8081/actuator/prometheus
 **/
@RestController
@RequestMapping("/custom/metrics")
@Tag(name = "CustomMetrics", description = "CustomMetricsController")
public class CustomMetricsController {

    @Autowired
    private MeterRegistry meterRegistry;

    /**
     * 订单请求测试
     * http://localhost:8081/custom/metrics/order/1
     */
    @GetMapping("/order/{appId}")
    @Operation(summary = "get order")
    public String orderTest(@PathVariable("appId") String appId) {
        Counter.builder("metrics.request.count").tags("apiCode", "order").register(meterRegistry).increment();
        return "order请求成功：" +appId ;
    }

    /**
     * 产品请求测试
     */
    @GetMapping("/product/{appId}")
    @Operation(summary = "get product")
    public String productTest(@PathVariable("appId") String appId) {
        Counter.builder("metrics.request.count").tags("apiCode", "product").register(meterRegistry).increment();
        return "product请求成功：" +appId ;
    }
}

